<?php

namespace app\api\business;

use app\common\lib\ChooseClass;
use app\common\lib\Number;

class Sms
{
    public static function sendCode(string $phoneNumber, $len, $type = 'ali')
    {
        // 获取随机数验证码验证码
        $code = Number::getCode($len);
        // 利用工厂模式获取某个sms类
        $className = ChooseClass::smsClassStat();
        $smsClass = ChooseClass::initClass($type, $className);
        $sms = $smsClass::sendCode($phoneNumber, $code);
        if ($sms) {
            cache(config('redis.prefix') . $phoneNumber, $code, config('redis.time'));
        }
        return $sms;
    }
}
